# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re,sys
reload(sys)
sys.setdefaultencoding('utf-8')

sys.path.append("\TestCase\public")
from public import *

class Process(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.hotent.org:10080/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_addprocess(self):
        driver = self.driver
        login.login(driver)
        smwait.smwait(driver.find_element_by_id,"leftTree_12_a")
        driver.find_element_by_id("leftTree_12_a").click()
        # 切换iframe到目标控件所在的frame
        time.sleep(8)
        driver.switch_to_frame("4")
        # print "find iframe 4"
        driver.implicitly_wait(10)
        driver.switch_to_frame("defFrame")
        # print "find iframe defFrame"
        driver.implicitly_wait(10) 
        driver.find_element_by_link_text(u"请假流程").click()
        time.sleep(3)
        # 切换浏览器窗口
        # print driver.current_window_handle
        swWindow.swWindow(driver)
        time.sleep(3)
        # driver.find_element_by_name("m:qj:sqrbm").click()
        driver.find_element_by_css_selector(".link.org").click()
        driver.implicitly_wait(10)
        # print driver.current_window_handle     
        # driver.find_element_by_id("orgTree_5_span")
        driver.switch_to_frame("orgFrame")
        driver.switch_to_frame("ligerwindow1499931683783")
        driver.find_element_by_xpath("//*[@id='sysOrgItem']/tbody/tr[5]/td[1]/input[1]").click()

        time.sleep(3)

    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()